package controler.p3_fitnessapp;

import nutrients.p3_fitnessapp.Nutrientscalc;
import unteractivities.p3_fitnessapp.UActNutrients2;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioGroup;

/**
 * 
 * @author jdyck, tcockx, mkuhlmay
 * 
 */
public class ActNutrients extends Activity {

	/*
	 * ==========================================================================
	 * Globale Variablen
	 * ========================================================
	 */

	/*
	 * ==========================================================================
	 * Android Methoden ========================================================
	 */

	/**
	 * Naehrstoffkalkulator XML aufrufen
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_nutrients_calc);
	}

	/*
	 * ==========================================================================
	 * Benutzer Interaktion (Buttons ... )
	 * ========================================================
	 */

	public void onButtonClick(View view) {

		/*
		 * Variablen
		 */

		EditText gewicht = (EditText) findViewById(R.id.edit_weight);
		EditText groesse = (EditText) findViewById(R.id.edit_heigth);

		// int weight = (int) gewicht.getText().parseInt();

		int weight = Integer.parseInt(gewicht.getText().toString());
		int heigth = Integer.parseInt(groesse.getText().toString());

		String phase = "";
		String bodytype = "";

		Log.e(null, "gewicht : " + weight);

		// TODO Berechnung der Nährstoffe
		// TODO Aufrufen der neuen Activity

		/*
		 * ToDo Button implementieren Klick auf weiter öffnet ActNutrients2
		 */

		switch (view.getId()) {
		case R.id.btn_next_nutrient:

			/*
			 * Radiobutton Phase auslesen
			 */

			RadioGroup rb_phase = (RadioGroup) findViewById(R.id.rg_phase);
			RadioGroup rb_bodytype = (RadioGroup) findViewById(R.id.rg_type);

			switch (rb_bodytype.getCheckedRadioButtonId()) {
			case R.id.rb_ecto:
				Log.d(null, "RB_ekto");
				bodytype = "Ektomorph";
				break;

			case R.id.rb_endo:
				bodytype = "Endomorph";
				Log.d(null, "RB_endo");

				break;

			case R.id.rb_meso:
				bodytype = "Mesomorph";
				Log.d(null, "RB_meso");

				break;

			default:
				Log.e(null, "keine phase gewählt");

				break;
			}

			/*
			 * Radiobutton Typ auslesen
			 */

			switch (rb_phase.getCheckedRadioButtonId()) {
			case R.id.rb_build:
				phase = "Aufbau";
				Log.d(null, "RB_aufbau");

				break;
			case R.id.rb_definition:
				phase = "Definition";
				Log.d(null, "RB_def");

				break;
			case R.id.rb_competition:
				phase = "Wettkampf";
				Log.d(null, "RB_comp");

				break;

			default:
				Log.e(null, "kein typ gewählt");

				break;
			}

//			Nutrientscalc calc = new Nutrientscalc();


//
//			Log.d(null, "Calculate BMI " + calc.calculateBMI(heigth, weight));
//
//			// smr berechnen und in Objekt schreiben
//			calc.set_smrLight(calc.calculateSMRLight(weight));
//
//			// bmi berechnen und in Objekt schreiben
//
//			// Berechnung
//
//			calc.calculateDetailed(phase, bodytype);
//			
//			
//			Log.d(null, "SmrLight " + calc.get_smrLight());
//			Log.d(null, "SmrLight " + calc.calculateSMRLight(weight));
//
//			// calc.calculateDetailed();

//			Log.d(null, "Calculate BMI " + calc.calculateBMI(heigth, weight));

//			Log.d(null, "Calculate BMI " + calc.calculateBMI(heigth, weight));

			// smr berechnen und in Objekt schreiben
			
//			calc.set_smrLight(calc.calculateSMRLight(weight));

			// bmi berechnen und in Objekt schreiben

			// Berechnung

//			calc.calculateDetailed(phase, bodytype);
			
			
//			Log.d(null, "SmrLight " + calc.calculateSMRLight(weight));



			
			// Intent aufbauen
			
			Intent intent = new Intent();
			
			intent.setClassName(getPackageName(), "unteractivities.p3_fitnessapp.UActNutrients2");
			
			/*
			 * smrlight
			 * weight
			 * heigth
			 */
			
			
			
			intent.putExtra("bodytype", bodytype);
			intent.putExtra("phase", phase);
			intent.putExtra("weight", weight);
			intent.putExtra("heigth", heigth);
//			intent.putExtra("smrlight", calc.calculateSMRLight(weight));

			
			
			startActivity(intent);

			break;

		default:
			break;
		}

	}

	/*
	 * ==========================================================================
	 * Eigene Methoden ========================================================
	 */

	/*
	 * ==========================================================================
	 * Debug Methoden ========================================================
	 */

	/*
	 * ==========================================================================
	 * Getter und Setter
	 * ========================================================
	 */

}
